﻿namespace ClassLibrary.DataLayer.DataObjects
{
    using ClassLibrary.BusinessLayer.BusinessObjects;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;

    public class ProcedureSetTmpltDAO : IProcedureSetTmpltDAO
    {
        public bool DeleteProcedureSetTmplt(ProcedureSetTmplt clsProcedureSetTmplt)
        {
            return clsProcedureSetTmplt.Save("D");
        }

        public IList<ProcedureSetTmplt> GetProcedureSetTmplt(ProcedureSetTmplt clsProcedureSetTmplt)
        {
            DataTable dt = Db.GetDataTable(clsProcedureSetTmplt.CreateGetCommandParameters());
            clsProcedureSetTmplt.LoadDataToCollection(dt.Rows[0]);
            if (dt.Rows[0] == null)
            {
                throw new Exception("ProcedureSetTmplt doesn't exist");
            }
            IList<ProcedureSetTmplt> list = new List<ProcedureSetTmplt>();
            list.Add(clsProcedureSetTmplt);
            return list;
        }

        public IList<ProcedureSetTmplt> GetProcedureSetTmplt(string procedureSetTmplt)
        {
            ProcedureSetTmplt clsProcedureSetTmplt = new ProcedureSetTmplt();
            clsProcedureSetTmplt._HeadingSet = procedureSetTmplt;
            return this.GetProcedureSetTmplt(clsProcedureSetTmplt);
        }

        public IList<ProcedureSetTmplt> GetsProcedureSetTmplt()
        {
            ProcedureSetTmplt clsProcedureSetTmplt = new ProcedureSetTmplt();
            IDataReader dtReader = Db.GetDataReader(clsProcedureSetTmplt.CreateGetsCommandParameters());
            IList<ProcedureSetTmplt> list = new List<ProcedureSetTmplt>();
            while (dtReader.Read())
            {
                clsProcedureSetTmplt = new ProcedureSetTmplt();
                clsProcedureSetTmplt.LoadDataToCollection(dtReader);
                list.Add(clsProcedureSetTmplt);
            }
            return list;
        }

        public DataTable GetsProcedureSetTmplt(string SPName, DbParameter[] param)
        {
            ProcedureSetTmplt clsProcedureSetTmplt = new ProcedureSetTmplt();
            return Db.GetDataTable(clsProcedureSetTmplt.GetsDataReader(SPName, param));
        }

        public bool InsertProcedureSetTmplt(ProcedureSetTmplt clsProcedureSetTmplt)
        {
            return clsProcedureSetTmplt.Save("I");
        }

        public int InsertProcedureSetTmpltReturnIdentity(ProcedureSetTmplt clsProcedureSetTmplt)
        {
            return clsProcedureSetTmplt.Save("I", true);
        }

        public string InsertProcedureSetTmpltReturnOutput(ProcedureSetTmplt clsProcedureSetTmplt)
        {
            return clsProcedureSetTmplt.Save("I", "@ProcedureSetTmpltID");
        }

        public IList<ProcedureSetTmplt> ListProcedureSetTmplt(ProcedureSetTmplt clsProcedureSetTmplt)
        {
            IDataReader dtReader = Db.GetDataReader(clsProcedureSetTmplt.CreateListCommandParameters());
            IList<ProcedureSetTmplt> list = new List<ProcedureSetTmplt>();
            while (dtReader.Read())
            {
                ProcedureSetTmplt clsProcedureSetTmplts = new ProcedureSetTmplt();
                clsProcedureSetTmplts.LoadDataToCollection(dtReader);
                list.Add(clsProcedureSetTmplts);
            }
            return list;
        }

        public IList<ProcedureSetTmplt> ListProcedureSetTmplt(string procedureSetTmplt)
        {
            ProcedureSetTmplt clsProcedureSetTmplt = new ProcedureSetTmplt();
            clsProcedureSetTmplt._HeadingSet = procedureSetTmplt;
            return this.ListProcedureSetTmplt(clsProcedureSetTmplt);
        }

        public bool UpdateProcedureSetTmplt(ProcedureSetTmplt clsProcedureSetTmplt)
        {
            return clsProcedureSetTmplt.Save("U");
        }

        public int UpdateProcedureSetTmplt(string SPName, DbParameter[] param)
        {
            ProcedureSetTmplt clsProcedureSetTmplt = new ProcedureSetTmplt();
            return Db.ExecuteNonQuery(clsProcedureSetTmplt.UpdateQuery(SPName, param));
        }
    }
}

